package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseSurfMinVo;
import com.manage.modules.bo.TBaseSurfMinQueryBo;
import com.manage.modules.bo.TBaseSurfMinAddBo;
import com.manage.modules.bo.TBaseSurfMinEditBo;
import com.manage.modules.service.ITBaseSurfMinService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 地面分钟要素Controller
 *
 * @author wx
 * @date 2021-09-08
 */
@Api(value = "地面分钟要素控制器", tags = {"地面分钟要素管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/surfMin")
public class TBaseSurfMinController extends BaseController {

    private final ITBaseSurfMinService iTBaseSurfMinService;

    /**
     * 查询最新一条地面要素
     *
     * @return
     */
    @GetMapping("/listMap")
    public AjaxResult listMap() {
        return AjaxResult.success(iTBaseSurfMinService.listMap());
    }

    /**
     * 查询地面分钟要素列表
     */
    @ApiOperation("查询地面分钟要素列表")
    @PreAuthorize("@ss.hasPermi('modules:surfMin:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseSurfMinVo> list(TBaseSurfMinQueryBo bo) {
        startPage();
        List<TBaseSurfMinVo> list = iTBaseSurfMinService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出地面分钟要素列表
     */
    @ApiOperation("导出地面分钟要素列表")
    @PreAuthorize("@ss.hasPermi('modules:surfMin:export')")
    @Log(title = "地面分钟要素", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseSurfMinVo> export(TBaseSurfMinQueryBo bo) {
        List<TBaseSurfMinVo> list = iTBaseSurfMinService.queryList(bo);
        ExcelUtil<TBaseSurfMinVo> util = new ExcelUtil<TBaseSurfMinVo>(TBaseSurfMinVo.class);
        return util.exportExcel(list, "地面分钟要素");
    }

    /**
     * 获取地面分钟要素详细信息
     */
    @ApiOperation("获取地面分钟要素详细信息")
    @PreAuthorize("@ss.hasPermi('modules:surfMin:query')")
    @GetMapping("/{surfId}")
    public AjaxResult<TBaseSurfMinVo> getInfo(@PathVariable("surfId") Long surfId) {
        return AjaxResult.success(iTBaseSurfMinService.queryById(surfId));
    }

    /**
     * 新增地面分钟要素
     */
    @ApiOperation("新增地面分钟要素")
    @PreAuthorize("@ss.hasPermi('modules:surfMin:add')")
    @Log(title = "地面分钟要素", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseSurfMinAddBo bo) {
        return toAjax(iTBaseSurfMinService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改地面分钟要素
     */
    @ApiOperation("修改地面分钟要素")
    @PreAuthorize("@ss.hasPermi('modules:surfMin:edit')")
    @Log(title = "地面分钟要素", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseSurfMinEditBo bo) {
        return toAjax(iTBaseSurfMinService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除地面分钟要素
     */
    @ApiOperation("删除地面分钟要素")
    @PreAuthorize("@ss.hasPermi('modules:surfMin:remove')")
    @Log(title = "地面分钟要素", businessType = BusinessType.DELETE)
    @DeleteMapping("/{surfIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] surfIds) {
        return toAjax(iTBaseSurfMinService.deleteWithValidByIds(Arrays.asList(surfIds), true) ? 1 : 0);
    }
}
